package com.mccken.practice.top100.Top_30$.Top_36;

import com.mccken.practice.top100.TreeNode;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-03-05 12:57
 **/
public class InvertTree {

	public TreeNode invertTree(TreeNode root) {
		
		if (root == null) {
			return null;
		} else {
			if (root.right != null) {
				invertTree(root.right);
			}

			if (root.left != null) {
				invertTree(root.left);
			}

			TreeNode tempNode = root.right;
			root.right = root.left;
			root.left = tempNode;	
		}
		
		return root;
	}

	public void temp(TreeNode node) {

		if (node == null) {
			return;
		}

		if (node.right != null) {
			temp(node.right);
		}
		
		if (node.left != null) {
			temp(node.left);
		}

		TreeNode tempNode = node.right;
		node.right = node.left;
		node.left = tempNode;
		
	}
}
